package cn.lrwjz.androidguide;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;

import java.util.ArrayList;
import java.util.List;

import cn.lrwjz.androidguide.adapter.ComponentAdapter;
import cn.lrwjz.androidguide.model.ComponentItem;
import cn.lrwjz.androidguide.ui.AppBarActivity;
import cn.lrwjz.androidguide.ui.BadgeActivity;
import cn.lrwjz.androidguide.ui.BottomAppBarActivity;
import cn.lrwjz.androidguide.ui.BottomNavigationActivity;
import cn.lrwjz.androidguide.ui.BottomSheetActivity;
import cn.lrwjz.androidguide.ui.ButtonsActivity;
import cn.lrwjz.androidguide.ui.CardActivity;
import cn.lrwjz.androidguide.ui.CarouselActivity;
import cn.lrwjz.androidguide.ui.CheckboxActivity;
import cn.lrwjz.androidguide.ui.ChipActivity;
import cn.lrwjz.androidguide.ui.DatePickerActivity;
import cn.lrwjz.androidguide.ui.DialogActivity;
import cn.lrwjz.androidguide.ui.DividerActivity;
import cn.lrwjz.androidguide.ui.DrawerActivity;
import cn.lrwjz.androidguide.ui.FabActivity;
import cn.lrwjz.androidguide.ui.GridActivity;
import cn.lrwjz.androidguide.ui.ListActivity;
import cn.lrwjz.androidguide.ui.MenuActivity;
import cn.lrwjz.androidguide.ui.NavigationRailActivity;
import cn.lrwjz.androidguide.ui.ProgressIndicatorActivity;
import cn.lrwjz.androidguide.ui.RadioButtonActivity;
import cn.lrwjz.androidguide.ui.SideSheetActivity;
import cn.lrwjz.androidguide.ui.SliderActivity;
import cn.lrwjz.androidguide.ui.SnackbarActivity;
import cn.lrwjz.androidguide.ui.SwitchActivity;
import cn.lrwjz.androidguide.ui.TabsActivity;
import cn.lrwjz.androidguide.ui.TextFieldActivity;
import cn.lrwjz.androidguide.ui.TimePickerActivity;
import cn.lrwjz.androidguide.ui.CoordinatorLayoutActivity;
import cn.lrwjz.androidguide.ui.exmple.FragmentActivity;
import cn.lrwjz.androidguide.ui.exmple.HttpActivity;
import cn.lrwjz.androidguide.ui.exmple.IntentActivity;
import cn.lrwjz.androidguide.ui.exmple.SQLiteActivity;
import cn.lrwjz.androidguide.ui.exmple.SharedPreferencesActivity;
import cn.lrwjz.androidguide.ui.RecyclerViewActivity;
import cn.lrwjz.androidguide.ui.ViewPagerActivity;
import cn.lrwjz.androidguide.ui.exmple.ViewPagerWithNavActivity;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private ComponentAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MaterialToolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        recyclerView = findViewById(R.id.recyclerView);
        // 瀑布流效果
//        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        // 网格布局
//        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        // 线性布局
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        BottomNavigationView bottomNav = findViewById(R.id.bottomNavigation);
        // 底部导航栏点击事件
        bottomNav.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                int itemId = item.getItemId();
                if (itemId == R.id.nav_home) {
                    adapter = new ComponentAdapter(getComponentList());
                    recyclerView.setAdapter(adapter);
                    return true;
                } else if (itemId == R.id.nav_example) {
                    adapter = new ComponentAdapter(getComponentList1());
                    recyclerView.setAdapter(adapter);
                    return true;
                }
                return false;
            }
        });

        // 默认选中首页
        bottomNav.setSelectedItemId(R.id.nav_home);

    }

    private List<ComponentItem> getComponentList() {
        List<ComponentItem> items = new ArrayList<>();

        items.add(new ComponentItem("App Bar", "顶部应用栏，用于标题、导航和操作按钮", AppBarActivity.class));
        items.add(new ComponentItem("BottomAppBar", "底部应用栏，提供导航和操作按钮", BottomAppBarActivity.class));
        items.add(new ComponentItem("Bottom Navigation", "底部导航栏，支持3-5个主要功能入口", BottomNavigationActivity.class));
        items.add(new ComponentItem("Navigation Rail", "侧边导航栏，适合平板/桌面设备", NavigationRailActivity.class));
        items.add(new ComponentItem("Drawer", "侧滑抽屉，提供导航或设置选项", DrawerActivity.class));
        items.add(new ComponentItem("Menu", "菜单，提供各种类型的菜单选项", MenuActivity.class));
        items.add(new ComponentItem("Grid", "网格布局，展示结构化内容", GridActivity.class));
        items.add(new ComponentItem("Card", "卡片容器，用于信息展示和交互", CardActivity.class));
        items.add(new ComponentItem("List", "列表布局，显示单行或多行信息条目", ListActivity.class));
        items.add(new ComponentItem("Divider", "分割线，用于视觉分隔内容", DividerActivity.class));
        items.add(new ComponentItem("Tabs", "标签页，用于在相关内容间切换", TabsActivity.class));
        items.add(new ComponentItem("Dialog", "对话框，用于显示重要信息或请求用户输入", DialogActivity.class));
        items.add(new ComponentItem("Button", "各种按钮样式和用法", ButtonsActivity.class));
        items.add(new ComponentItem("FAB", "浮动操作按钮，用于表示页面的主要操作", FabActivity.class));
        items.add(new ComponentItem("RadioButton", "单选按钮，用于在一组选项中进行单选", RadioButtonActivity.class));
        items.add(new ComponentItem("Checkbox", "复选框，用于在一组选项中进行多选", CheckboxActivity.class));
        items.add(new ComponentItem("Chip", "标签，用于输入、选择、过滤或显示信息", ChipActivity.class));
        items.add(new ComponentItem("Badge", "徽章，用于显示状态、提醒或数字标记", BadgeActivity.class));
        items.add(new ComponentItem("Carousel", "轮播，用于展示一组相关内容", CarouselActivity.class));
        items.add(new ComponentItem("Progress Indicator", "进度指示器，用于显示操作的进度", ProgressIndicatorActivity.class));
        items.add(new ComponentItem("Slider", "滑块，用于从一个范围内选择值", SliderActivity.class));
        items.add(new ComponentItem("Snackbar", "提示条，用于显示简短的消息和操作", SnackbarActivity.class));
        items.add(new ComponentItem("Switch", "开关，用于切换单个选项的开启/关闭状态", SwitchActivity.class));
        items.add(new ComponentItem("TextField", "文本框，提供各种样式的输入框", TextFieldActivity.class));
        items.add(new ComponentItem("BottomSheet", "底部表，提供从屏幕底部滑出的面板", BottomSheetActivity.class));
        items.add(new ComponentItem("SideSheet", "侧边表，提供从屏幕侧边滑出的面板", SideSheetActivity.class));
        items.add(new ComponentItem("DatePicker", "日期选择器，提供日期选择和日期范围选择功能", DatePickerActivity.class));
        items.add(new ComponentItem("TimePicker", "时间选择器，提供12/24小时制时间选择功能", TimePickerActivity.class));
        items.add(new ComponentItem("RecyclerView", "列表视图，支持线性、网格和瀑布流布局", RecyclerViewActivity.class));
        items.add(new ComponentItem("ViewPage2", "页面滑动，用于引导页、轮播图以及处理嵌套滑动等", ViewPagerActivity.class));
        items.add(new ComponentItem("CoordinatorLayout", "协调布局，用于子视图之间的交互和协调", CoordinatorLayoutActivity.class));
//        items.add(new ComponentItem("Search", "搜索组件，提供搜索栏和搜索视图功能", SearchActivity.class));
        return items;
    }

    private List<ComponentItem> getComponentList1() {
        List<ComponentItem> items = new ArrayList<>();
        items.add(new ComponentItem("Intent", "页面跳转，显示跳转和隐式跳转", IntentActivity.class));
        items.add(new ComponentItem("Fragment", "页面碎片，构建动态和灵活的用户界面", FragmentActivity.class));
        items.add(new ComponentItem("SharedPreferences", "共享存储，轻量级的数据存储", SharedPreferencesActivity.class));
        items.add(new ComponentItem("SQLite", "本地存储，轻量级、嵌入式的关系型数据库", SQLiteActivity.class));
        items.add(new ComponentItem("HTTP", "网络请求，异步任务网络请请求和多线程通信", HttpActivity.class));
        items.add(new ComponentItem("ViewPage2", "页面滑动，用于引导页、轮播图以及处理嵌套滑动等", ViewPagerWithNavActivity.class));
        return items;
    }
} 